#include "WaterDropEmitter.h"
#include "Constants.h"

WaterDropEmitter::WaterDropEmitter(CubePileGrid * cubes, int numberOfDrops)
	:RandomTimeEmitter(cubes, MIN_WATER_EMIT_TIME, MAX_WATER_EMIT_TIME)
{
	numberOfDropsLeftToEmit = numberOfDrops;
	freeParticle = NULL;
}

//TODO: this belongs in a utility class for generating random numbers.  
// There's stuff like this all over the shop, move it to save yourself the trouble of maintaining it
int randomInt(int low, int high)
{
	int randomInt = rand() % high;
    if(randomInt < low)
    {
    	randomInt = low;	
    }
    return randomInt;
}

int someWhatRandom(int target, int maxVariance)
{
	int actualVariance = randomInt(0, maxVariance);
	return target + actualVariance - actualVariance/2;
}

void WaterDropEmitter::emitTo(CubePileGrid * cubePiles)
{
	freeParticle->alive = true;
	freeParticle->xPos = someWhatRandom(6, 20);
	freeParticle->yPos = someWhatRandom(10, 4);
	freeParticle->zPos = someWhatRandom(6, 20);
	freeParticle->yVel = someWhatRandom(5, 5) * -0.001;
	freeParticle->xVel = someWhatRandom(0, 5) * -0.001;
	freeParticle->zVel = someWhatRandom(0, 2) * -0.01;
}

bool WaterDropEmitter::isFinishedEmitting()
{
	//emission completion is controlled by the particle system
	return false;
}
